"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SocketClientMsgHandler = void 0;
const ErrorCode_1 = require("../../../config/ErrorCode");
const ServerConfig_1 = require("../../../config/ServerConfig");
const ResponseModel_1 = require("../../../model/ResponseModel");
const Logger_1 = require("../../utils/Logger");
const ProtoServerConfig_1 = require("../protocol/ProtoServerConfig");
const SocketConnectionManager_1 = require("./SocketConnectionManager");
class SocketClientMsgHandler {
    static onEventSocketGata(socketConnect, msg) {
        if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_login) {
            this.on_req_server_login(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_set_server_status) {
            this.req_server_set_server_status(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_is_in_server) {
            this.on_req_server_is_in_server(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_is_user_online) {
            this.on_req_server_is_user_online(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_onlie_club) {
            this.on_req_server_onlie_club(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_notify_delete_club_user) {
            this.on_req_server_notify_delete_club_user(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_notify_set_club_quanxian) {
            this.req_server_notify_set_club_quanxian(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_notify_club_freeze) {
            this.req_server_notify_club_freeze(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_notify_set_club_admin) {
            this.req_server_notify_set_club_admin(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_insertRoomTemplateModel) {
            this.on_req_server_insertRoomTemplateModel(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_deleteRoomTemplateModel) {
            this.on_req_server_deleteRoomTemplateModel(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_createRoom) {
            this.on_req_server_createRoom(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_joinRoom) {
            this.on_req_server_joinRoom(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_deleteRoom) {
            this.on_req_server_deleteRoom(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_leave_room) {
            this.on_req_server_leave_room(socketConnect, msg);
        }
        else if (msg.protoName == ProtoServerConfig_1.ProtoServerConfig.req_server_notify_game_start) {
            this.on_req_server_notify_game_start(socketConnect, msg);
        }
    }
    static on_req_server_login(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let account = socketMsg.protoData["account"];
            new_conn.account = account;
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.code = ErrorCode_1.ErrorCode.Code.Suc;
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_login, respModel);
        });
    }
    static req_server_set_server_status(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let status = socketMsg.protoData["status"];
            ServerConfig_1.ServerConfig.nowServerConfig.status = status;
            let respModel = new ResponseModel_1.ResponseModel();
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_set_server_status, respModel);
        });
    }
    static on_req_server_is_user_online(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let userid = socketMsg.protoData["userid"];
            Logger_1.Logger.log("on_req_server_is_user_online==", socketMsg);
            let isOnline = false;
            if (userid && userid > 0) {
                isOnline = SocketConnectionManager_1.SocketConnectionManager.instance.isUserOnline(userid);
            }
            let result = {
                "isOnline": isOnline
            };
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_is_user_online, result);
        });
    }
    static on_req_server_is_in_server(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let account = socketMsg.protoData["account"];
            Logger_1.Logger.log("on_req_server_is_in_server==", socketMsg);
            let isIn = false;
            if (account && account != "") {
                SocketConnectionManager_1.SocketConnectionManager.instance.socketConnMap.forEach((conn, key) => {
                    if (conn.isLogin()) {
                        if (conn.account == account) {
                            isIn = true;
                            return;
                        }
                    }
                });
            }
            let result = {
                "isIn": isIn
            };
            Logger_1.Logger.log("on_req_server_is_in_server=222=", result);
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_is_in_server, result);
        });
    }
    static on_req_server_onlie_club(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let clubid = socketMsg.protoData["clubid"];
            let count = SocketConnectionManager_1.SocketConnectionManager.instance.getClubOnlineCount(clubid);
            let result = {
                "count": count
            };
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_onlie_club, result);
        });
    }
    static on_req_server_notify_delete_club_user(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let clubid = socketMsg.protoData["clubid"];
            let userid = socketMsg.protoData["userid"];
            let result = {
                "code": ErrorCode_1.ErrorCode.Code.Suc
            };
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_notify_delete_club_user, result);
        });
    }
    static req_server_notify_club_freeze(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let clubid = socketMsg.protoData["clubid"];
            let userid = socketMsg.protoData["userid"];
            let user_state = socketMsg.protoData["user_state"];
            let result = {
                "code": ErrorCode_1.ErrorCode.Code.Suc
            };
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_notify_set_club_quanxian, result);
        });
    }
    static req_server_notify_set_club_quanxian(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let clubid = socketMsg.protoData["clubid"];
            let userid = socketMsg.protoData["userid"];
            let quanxian = socketMsg.protoData["quanxian"];
            let result = {
                "code": ErrorCode_1.ErrorCode.Code.Suc
            };
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_notify_set_club_quanxian, result);
        });
    }
    static req_server_notify_set_club_admin(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let clubid = socketMsg.protoData["clubid"];
            let userid = socketMsg.protoData["userid"];
            let actor = socketMsg.protoData["actor"];
            let quanxian = socketMsg.protoData["quanxian"];
            let result = {
                "code": ErrorCode_1.ErrorCode.Code.Suc
            };
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_notify_set_club_admin, result);
        });
    }
    static on_req_server_insertRoomTemplateModel(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let result = {
                "code": ErrorCode_1.ErrorCode.Code.Suc
            };
            Logger_1.Logger.log("on_req_server_insertRoomTemplateModel");
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_insertRoomTemplateModel, result);
        });
    }
    static on_req_server_deleteRoomTemplateModel(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let id = socketMsg.protoData["id"];
            let result = {
                "code": ErrorCode_1.ErrorCode.Code.Suc
            };
            Logger_1.Logger.log("on_req_server_deleteRoomTemplateModel");
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_deleteRoomTemplateModel, result);
        });
    }
    static on_req_server_createRoom(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let room = socketMsg.protoData["room"];
            let result = {
                "code": ErrorCode_1.ErrorCode.Code.Suc
            };
            Logger_1.Logger.log("on_req_server_createRoom", room);
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_createRoom, result);
        });
    }
    static on_req_server_joinRoom(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let room_id = socketMsg.protoData["room_id"];
            let playerObj = socketMsg.protoData["player"];
            let result = new ResponseModel_1.ResponseModel();
            Logger_1.Logger.log("on_req_server_joinRoom", room_id);
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_joinRoom, result);
        });
    }
    static on_req_server_deleteRoom(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let room_id = socketMsg.protoData["room_id"];
            let result = {
                "code": ErrorCode_1.ErrorCode.Code.Suc
            };
            Logger_1.Logger.log("on_req_server_deleteRoom", room_id);
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_deleteRoom, result);
        });
    }
    static on_req_server_leave_room(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let room = socketMsg.protoData["room"];
            let result = {
                "code": ErrorCode_1.ErrorCode.Code.Suc
            };
            Logger_1.Logger.log("on_req_server_leave_room", room);
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_leave_room, result);
        });
    }
    static on_req_server_notify_game_start(new_conn, socketMsg) {
        return __awaiter(this, void 0, void 0, function* () {
            let room = socketMsg.protoData["room"];
            let result = {
                "code": ErrorCode_1.ErrorCode.Code.Suc
            };
            Logger_1.Logger.log("on_req_server_notify_game_start", room);
            new_conn.createMsgToClient(socketMsg.reqId, ProtoServerConfig_1.ProtoServerConfig.req_server_notify_game_start, result);
        });
    }
}
exports.SocketClientMsgHandler = SocketClientMsgHandler;
